
//
//  CTNavViewController.m
//  jdforme
//
//  Created by leo on 2017/5/18.
//  Copyright © 2017年 leojingdong.com. All rights reserved.
//
#define CTNavigationBarTitleFont [UIFont systemFontOfSize:18]
#define CTNavigationBarButtonFont [UIFont systemFontOfSize:14]
#define CTKeyWindow [UIApplication sharedApplication].keyWindow
#import "CTNavViewController.h"

@interface CTNavViewController ()<UINavigationControllerDelegate>

@end

@implementation CTNavViewController

+(void)initialize {
    UIBarButtonItem *allNavItems = [UIBarButtonItem appearanceWhenContainedIn:self, nil];
    NSMutableDictionary *textAttributeButton = [NSMutableDictionary dictionary];
    textAttributeButton[NSForegroundColorAttributeName] = [UIColor grayColor];
    textAttributeButton[textAttributeButton] = CTNavigationBarButtonFont;
    [allNavItems setTitleTextAttributes:textAttributeButton forState:UIControlStateNormal];
    //获取全局的navBar
    UINavigationBar *allNavBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    NSMutableDictionary *textAttributeForTitle = [NSMutableDictionary dictionary];
    textAttributeForTitle[NSFontAttributeName] = CTNavigationBarTitleFont;
    [allNavBar setTitleTextAttributes:textAttributeForTitle];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_white_top"] forBarMetrics:UIBarMetricsDefault];
    self.delegate = self;
}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
//    UITabBarController *tabbarController = (UITabBarController *)CTKeyWindow.rootViewController;
    UITabBarController *tabbarController = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    for (UIView *view in tabbarController.tabBar.subviews) {
        for (UIView *subviews in view.subviews) {
            if ([subviews isKindOfClass:NSClassFromString(@"_UIBadgeView")]) {
                [subviews removeFromSuperview];
            }
        }
    }
}
@end
